This repository was archived by the owner on May 15, 2026. It is now read-only.
fix: coerce write_to_file content to string when model sends object - #11041
Draft
ghost wants to merge 1 commit into
Draft
fix: coerce write_to_file content to string when model sends object#11041ghost wants to merge 1 commit into
ghost wants to merge 1 commit into
Conversation
Some models (e.g., GLM 4.7 via OpenAI Compatible API) incorrectly pass the content parameter as a JSON object instead of a string when calling the write_to_file tool. This causes processing to break silently. This fix adds defensive type coercion in NativeToolCallParser to: 1. Detect when content is not a string 2. Convert it to a formatted JSON string using JSON.stringify 3. Log a clear warning message so users understand what happened This follows the existing pattern for type coercion (e.g., coerceOptionalBoolean for booleans). Fixes #11040
Author
Review completed. No issues found. The implementation is clean and well-structured:
Mention @roomote in a comment to request specific changes to this pull request or fix all unresolved issues. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to subscribe to this conversation on GitHub.
Already have an account?
Sign in.
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Related GitHub Issue
Closes: #11040
Description
This PR attempts to address Issue #11040 where some models (e.g., GLM 4.7 via OpenAI Compatible API) incorrectly pass the
contentparameter as a JSON object instead of a string when calling thewrite_to_filetool, causing processing to break silently.Key implementation details:
coerceContentToString()helper method inNativeToolCallParser.tsthat handles type coercion gracefullyparseToolCall()andcreatePartialToolUse()methods to use this helper for thewrite_to_filetoolcoerceOptionalBooleanfor booleans)Feedback and guidance are welcome.
Test Procedure
Unit tests added: New test cases in
NativeToolCallParser.spec.tscovering:Run tests:
Manual verification: With a model like GLM 4.7 that sends object content, the tool should now work instead of breaking silently, and a warning will be logged.
Pre-Submission Checklist
Documentation Updates
Additional Notes
This is a defensive fix that gracefully handles model misbehavior without changing the expected interface. Models that correctly output strings are unaffected.
Important
Adds content coercion to string for
write_to_filetool inNativeToolCallParser.ts, with tests for various content types.coerceContentToString()inNativeToolCallParser.tsto convert non-string content to JSON string forwrite_to_filetool.parseToolCall()andcreatePartialToolUse()inNativeToolCallParser.tsto usecoerceContentToString().NativeToolCallParser.spec.tsforwrite_to_filetool to verify content coercion from object, array, and number to string.This description was created by
for 09e8f31. You can customize this summary. It will automatically update as commits are pushed.